package com.example.utils;

import org.mockito.internal.matchers.InstanceOf;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ZhengDing
 * @date 2022/2/21 21:39
 */

public class StringUtils {
    
    private static List<String> delimitedStringToStringList(String delimitedString) {
        String[] split = delimitedString.split(",");
        List<String> itemList = Arrays.stream(split).map(item -> {
            return item.trim();
        }).collect(Collectors.toList());
        return itemList;
    }
    
    private static String[] delimitedStringToStringArray(String delimitedString) {
        List<String> stringList = delimitedStringToStringList(delimitedString);
        String[] sa = stringList.toArray(new String[0]);
        return sa;
    }
    
    public static void main(String[] args) {
        for (String item : delimitedStringToStringList(" hello_world, user    , book ")) {
            System.out.println(item + "|");
        }
        
        test();
        
        test(new String[]{"hello", "world"});
        
        String heads = " hello, xf";
        test(delimitedStringToStringArray(heads));
    }
    
    public static void test(String... vars) {
        System.out.println(vars);
    }
    
}
